package com.juzi.wopu.query;

import java.util.List;
// 告诉它对被批注的代码元素内部的某些警告保持静默。 
@SuppressWarnings("rawtypes")
public class PageList {	
	
	private List rows;

	private int currentPage;

	private int pageSize;

	private int totalcount;

	private int totalPage;
	
	public PageList(){}
	
	public PageList(int currentPage, int pageSize, int totalcount) {
		this.currentPage=currentPage <1?1:currentPage;
		this.pageSize = pageSize<1?10:pageSize;
		this.totalcount = totalcount;
		
		this.totalPage=(int)Math.ceil(this.totalcount * 1.0/this.pageSize);
		
		this.currentPage=this.currentPage>this.totalPage?this.totalPage:this.currentPage;
	}
	
	public int getBegin(){
		if(currentPage==1){
			return 1;
		}else{
			return (currentPage-1)*pageSize+1;
		}
	}
	
	public int getEnd(){
		if(currentPage==totalPage){
			return totalcount;
		}else{
			return currentPage*pageSize;
		}
	}
	
	public String getPage(){
		StringBuilder builder=new StringBuilder();
		if(currentPage==1){
			builder.append("<li class='prev disabled'><a href='#'>首页</a></li>");
			builder.append("<li class='prev disabled'><a href='#'>上一页</a></li>");
		}else{
			builder.append("<li class='prev'><a href='#' onclick='go(1);'>首页</a></li>");
			builder.append("<li class='prev'><a href='#' onclick='go("+(currentPage-1)+");'>上一页</a></li>");
		}
		
		for(int i=1;i<=totalPage;i++){
			if(i==currentPage){
				builder.append("<li class='active'><a href='#'>"+i+"</a></li>");
			}else{
				builder.append("<li><a href='#' onclick='go("+i+")'>"+i+"</a></li>");
			}
		}
		
		if(currentPage==totalPage){
			builder.append("<li class='next disabled'><a href='#'>上一页</a></li>");
			builder.append("<li class='next disabled'><a href='#'>首页</a></li>");
		}else{
			builder.append("<li class='next'><a href='#' onclick='go("+(currentPage+1)+");'>下一页</a></li>");
			builder.append("<li class='next'><a href='#' onclick='go("+totalPage+");'>尾页</a></li>");
		}
		return builder.toString();
	}
	
	public int getTotalcount() {
		return totalcount;
	}
	public void setTotalcount(int totalcount) {
		this.totalcount = totalcount;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	@Override
	public String toString() {
		return "PageList [totalcount=" + totalcount + ", currentPage=" + currentPage + ", pageSize="
				+ pageSize + ", totalPage=" + totalPage +", rows.size=" + rows.size() + "]";
	}
}